"""
数据包模型
创建时间：2025-09-12
作者：开发团队
目的：定义数据包数据模型
"""

from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Text
from sqlalchemy.orm import relationship
from datetime import datetime, timezone
from ..core.database import Base


class DataPackage(Base):
    """数据包模型"""
    
    __tablename__ = "data_packages"
    
    # 基础字段
    id = Column(Integer, primary_key=True, index=True, autoincrement=True)
    content_types = Column(Text)  # JSON格式存储包含的数据类型
    file_path = Column(String(255))
    file_size = Column(Integer)
    encryption_status = Column(String(20), nullable=False)
    download_count = Column(Integer, default=0)
    created_by = Column(Integer, ForeignKey("users.id"), nullable=False, index=True)
    created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc), nullable=False)
    
    # 关系
    creator = relationship("User", back_populates="data_packages")
    
    def __repr__(self):
        return f"<DataPackage(id={self.id}, encryption_status='{self.encryption_status}')>"